package com.sun.designpatternsdemo.base

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding

/**
 * 版权：xx公司 版权所有
 * @author sun
 * 版本：1.0
 * 创建日期：2021/6/29 14:40
 * 描述：基类
 *
 */
abstract class BaseActivity<DB:ViewDataBinding>:AppCompatActivity() {
    lateinit var mDataBind: DB
    /**
     * 是否需要使用DataBinding 供子类BaseVmDbActivity修改，用户请慎动
     */
    private var isUserDb = true
    abstract fun layoutId(): Int
    abstract fun initView(savedInstanceState: Bundle?)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        if (isUserDb){
            initDataBind()
        }else{
            setContentView(layoutId())
        }
        initView(savedInstanceState)
    }

    private fun initDataBind(){
        mDataBind = DataBindingUtil.setContentView(this,layoutId())
        mDataBind.lifecycleOwner = this
    }

    fun userDataBinding(isUserDb: Boolean) {
        this.isUserDb = isUserDb
    }
}